import axios from 'axios'
const instance = axios.create({
  baseURL: 'http://localhost:3000',
  timeout: 6000
});
// 添加请求拦截器：若本地有 token，则附加到 Authorization 头
instance.interceptors.request.use(function (config) {
  const token = localStorage.getItem('token')
  if (token) {
    if (!config.headers) config.headers = {}
    (config.headers as any).Authorization = `Bearer ${token}`
  }
  return config
}, function (error) {
  return Promise.reject(error)
})
 
// 添加响应拦截器（返回完整响应，方便获取 status 等）
instance.interceptors.response.use(function (response) {
    return response;
  }, function (error) {
    return Promise.reject(error);
  });
export default instance